<include file="public/header"/>
<style>
    .container{margin-left: 0px;margin-right: 0px;}
</style>
</head>
<body>
<div class="wrap js-check-wrap">
    <!-- 内容导航 -->
    <ul class="nav nav-tabs">
        <foreach name="allTables" key="table" item="field">
            <php>if($field['relate_level']==1) continue;</php>
            <li <if condition="$table_name eq $table">class="active"</if>>
                <a href="{:cmf_plugin_url('Modules://Content/index',['modules_id'=>$modules_id, 'table_name'=>$table])}"
                   alt="{$field['Comment']}">{$field['Comment']}<if condition="$field['relate_level'] eq 2">列表</if></a>
            </li>
            <if condition="empty($field['pinyin'])">
                <li <if condition="$table_name eq $table">class="active"</if> >
                <a href="{:cmf_plugin_url('Modules://Content/edit',['modules_id'=>$modules_id,'table_name'=>$table])}">添加/编辑</a></li>
            </if>
        </foreach>
    </ul>

    <form action="{:cmf_plugin_url('Modules://content/editPost')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
        <input type="hidden" name="modules_id" value="{$modules_id}">
        <input type="hidden" name="table_name" value="{$table_name}">
        <if condition="isset($id)"><input type="hidden" name="id" value="{$id}"></if>

        <div class="row">
            <div class="col-md-2 tabbable tabs-left">
                <!-- Nav tabs -->
                <ul class="nav nav-tabs nav-pills nav-stacked" role="tablist">
                    <foreach name="allTables" key="table" item="field">
                        <if condition="empty($field['pinyin'])">
                            <li class="nav-item <php>if(empty($table_name) || $field['table_name'] == $table_name) echo 'active';</php>">
                                <a class="nav-link" data-toggle="tab" href="#tab-{$table}">{$field['Comment']}</a>
                            </li>
                        <elseif condition="$field['relate_level'] eq 1"/>
                            <li class="nav-item <php>if($field['table_name'] == $table_name) echo 'active';</php>">
                                <a class="nav-link" data-toggle="tab" href="#tab-{$table}">{$field['Comment']}</a>
                            </li>
                        <elseif condition="$field['relate_level'] eq 2"/>
                            <li class="nav-item <php>if($field['table_name'] == $table_name) echo 'active';</php>">
                                <!--<a class="nav-link nav-iframe" data-table="{$table}" data-toggle="tab" href="#tab-{$table}">{$field['Comment']} -></a>-->
                                <a  class="nav-link" href="javascript:parent.openIframeLayer('{:cmf_plugin_url('Modules://content/index',
                                ['modules_id'=>$modules_id,'table_name'=>$table,'itemid'=>$itemid,'modules_simple'=>1])}','{$field['Comment']}',{});">{$field['Comment']} -></a>
                            </li>
                        </if>
                    </foreach>
                </ul>
            </div>

            <div class="col-md-10">
                <div class="tab-content">
                    <php>\plugins\modules\lib\EditForm::init($allFieldName, $content, "__STATIC__");</php>
                    <foreach name="allTables" key="table" item="val">
                        <?php if(empty($val['relate_level']) && !empty($val['pinyin'])) continue;?>
                        <div id="tab-{$table}" class="tab-pane <php>if($table==$table_name) echo 'active';</php>" >
                            <if condition="!empty($val['control_edit']) && (empty($val['relate_level']) && empty($val['pinyin']) || $val['relate_level']==1)">
                                <div class="row">
                                    <div class="col-md-9"><!-- 这里是动态配置左边内容 -->
                                        <php>
                                            if(is_array($val['control_edit']))
                                            foreach($val['control_edit'] as $k=>$v){
                                                if(!isset($v['position']) || $v['position']!='right'){
                                                    \plugins\modules\lib\EditForm::start($v,$table);
                                                }
                                            }
                                        </php>
                                    </div>
                                    <div class="col-md-3"><!-- 这里是动态配置右边内容-->
                                        <table class="table table-bordered">
                                        <php>
                                            if(is_array($val['control_edit']))
                                                foreach($val['control_edit'] as $k=>$v){
                                                if(isset($v['position']) && $v['position']=='right'){
                                                    \plugins\modules\lib\EditForm::start($v,$table);
                                                }
                                            }
                                        </php>
                                        </table>
                                    </div>
                                </div>
                            <elseif condition="$val['relate_level'] eq 2"/>
                                <input type="hidden" id="url-{$val['table_name']}"
                                       data-url="{:cmf_plugin_url('Modules://content/index',['modules_id'=>$modules_id,'table_name'=>$table,'itemid'=>$itemid,'modules_simple'=>1])}"/>
                                <iframe style="width:100%; min-height:600px; display:inline;" frameborder="0" id="iframe-{$val['table_name']}"></iframe>
                            <else />
                                未配置任何字段!
                            </if>
                        </div>
                    </foreach><!--allFields end (主表、一对一、一对多)-->

                </div><!-- tab-content && Tab panes end-->
            </div><!--col-md-10  end-->
        </div>

        <br/><br/>
        <div class="navbar navbar-fixed-bottom" style="margin-left: 15px;">
                <button type="submit" class="btn btn-primary js-ajax-submit">保存</button>
            <if condition="$relate_level == 2">
                <a class="btn btn-default" href="{:cmf_plugin_url('Modules://content/index',['modules_id'=>$modules_id,'table_name'=>$table_name,'itemid'=>$itemid])}">返回</a>
            <else />
                <a class="btn btn-default" href="{:cmf_plugin_url('Modules://content/index',['modules_id'=>$modules_id,'table_name'=>$table_name])}">返回</a>
            </if>
        </div>
    </form>
</div>
<script src="__PLUGIN_TMPL__/public/assets/js/admin.js"></script>
<script>
    $('.nav-iframe').click(function (e) {
        e.preventDefault();
        var table_name = $(this).attr('data-table');
        var iframeobj = $('#iframe-' + table_name);
        iframeobj.attr('src', $('#url-' + table_name).attr('data-url'));
        $(this).tab('show');
    });
</script>
</body>
</html>